package com.example.yu.perfect_demo.viewholder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUtils {


    /**
     * 推荐
     */
    public static final String URL_RECOMMEND = "http://mobile.ximalaya.com/discovery-firstpage/v2/explore/ts-1535959506994?appid=0&categoryId=-2&device=android&deviceId=57cf4217-4dcc-364b-9845-40eaa02775bc&includeActivity=true&includeSpecial=true&inreview=false&network=wifi&operator=2&pullToRefresh=false&scale=1&version=6.5.16";

    public static String get(String address) {
        HttpURLConnection conn = null;
        BufferedReader br = null;
        try {
            URL url = new URL(address);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(5000);
            int responseCode = conn.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                return br.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                conn.disconnect();
            }
        }
        return null;
    }

}
